package com.google.code.ptrends.excel.entities;

public class Cell {

	private int index;
	private CellStyle style;
	private String value;

	private int fHashCode;

	public Cell() {
	}

	public Cell(int index, CellStyle style, String value) {
		this.index = index;
		this.style = style;
		this.value = value;
	}

	public int getIndex() {
		return index;
	}

	public void setIndex(int index) {
		this.index = index;
	}

	public CellStyle getStyle() {
		return style;
	}

	public void setStyle(CellStyle style) {
		this.style = style;
	}

	public String getValue() {
		return value;
	}

	public void setValue(String value) {
		this.value = value;
	}

	@Override
	public boolean equals(Object arg0) {
		if (arg0 == null)
			return false;
		if (!(arg0 instanceof Cell))
			return false;
		Cell obj = (Cell) arg0;
		boolean result = index == obj.getIndex();
		
		if (value != null)
			result &= value.equals(obj.getValue());
		else
			result &= obj.getValue() == null;
		
		if ( style != null)
			result &= style.equals(obj.getStyle());
		else
			result &= obj.getStyle() == null;
		
		return result;
	}

	@Override
	public int hashCode() {
		if (fHashCode == 0) {
			fHashCode = 7 + 11 * index;
			if (value != null)
				fHashCode ^= 23 * value.hashCode();
			if (style != null)
				fHashCode ^= 19 * style.hashCode();
		}
		return fHashCode;
	}

	@Override
	public String toString() {
		return value;
	}
}
